package com.kitty.game.pet.bean;

import com.kitty.game.pet.PetType;
import com.kitty.game.utils.Arith;
import com.kitty.common.utils.StaticParam;
import lombok.Getter;
import lombok.Setter;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 新的宠物配置对象
 */
@Getter
@Setter
public abstract class PetObject {
    private String name;
    private short icon;
    private List<String> zoon;//出现地图
    private String polar;
    private short level_req;//需求等级
    private short life;
    private short mana;
    private short speed;
    private short phy_attack;
    private short mag_attack;
    private List<String> skills;
    private byte capacity_level;//坐骑阶数
    private String targetNum;

    /**
     * 宠物类型
     */
    public abstract int getPetType();


    public byte getPolar(){
        List<String> polars = Arrays.asList("无","金","木","水","火","土");
        return (byte) polars.indexOf(polar);
    }
    /**
     * 只有神兽或者变异才有的附加属性
     */
    public abstract int getElitePetBasicAddByValue(int effect);

    public Map<String, Integer> getGrowInfo(boolean isUpgradeCheck, String effectType) {
        int effect =0;
        int range = 10;
        switch (effectType) {
            case "life":
                effect = getLife();
                break;
            case "mana":
                effect = getMana();
                break;
            case "speed":
                effect = getSpeed();
                range = 5;
                break;
            case "phy":
                effect = getPhy_attack();
                break;
            case "mag":
                effect = getMag_attack();
                break;
        }
        byte petTypeByName = StaticParam.getPetTypeByName(name);
        /**神兽变异没有大小值 都是满的*/
        if (getPetType() == PetType.ELITE || getPetType() == PetType.EPIC) {
            range = 0;
        }
        if(petTypeByName == 6 || petTypeByName == 7 || petTypeByName == 8){
            range = 0;
        }
        int additional = getElitePetBasicAddByValue(effect);

        Map<String, Integer> growInfo = new HashMap<>();
        int max = 0;
        int min = 0;
        /**取飞升属性的时候用的*/
        int maxUpgrade = 0;
        int minUpgrade = 0;

        if (isUpgradeCheck) {
            minUpgrade = getPerFlyUpgradeAddValue(effect + 40 - range, effectType);
            maxUpgrade = getPerFlyUpgradeAddValue(effect + 40 + range, effectType);
        }
        /**精怪和纪念没有野生，成长区间以宝宝成长区间为准*/
        if (getPetType() == PetType.JINGGUAI || getPetType() == PetType.JINIAN) {
            if (isUpgradeCheck) {
                minUpgrade = getPerFlyUpgradeAddValue(effect + 40, effectType);
            }
            min = effect + 40 + additional + minUpgrade;
        } else {
            min = effect + 40 - range + additional + minUpgrade;
        }

        max = effect + 40 + range + additional + maxUpgrade;
        growInfo.put("min", min);
        growInfo.put("max", max);
        return growInfo;
    }


    /**
     *  取飞升后增加成成长值
     *  第一个参数 当前的成长  第三个参数 成长的类型
     *  假如是普通宠物 气血成长 40满 当前只有38 那么飞升之后用38给他取飞升该有的属性
     */
    public int getPerFlyUpgradeAddValue(int basic, String effectType) {
        Map<String, Double> GROWTH = new HashMap<>();
        GROWTH.put("life", 1.2);
        GROWTH.put("mana", 1.1);
        GROWTH.put("speed", 1.3);
        GROWTH.put("mag", 1.2);
        GROWTH.put("phy", 1.2);
        double ds2;
        if (getPetType() == PetType.EPIC || getPetType() == PetType.ELITE) {
            ds2 = 1.2;
        } else if (getPetType() == PetType.JINGGUAI) {
            ds2 = 1.05;
        } else {
            ds2 = 1.0;
        }
        double ds1 = GROWTH.get(effectType);
        double addValue = 0;
        double value = Arith.mul((Arith.sub(Arith.mul(ds1 , ds2) , 1.0)) , (100 + basic - 40));
        if (getPetType() == PetType.EPIC || getPetType() == PetType.ELITE) {
            addValue = value - Math.floor( Arith.mul(basic , 0.2));
        } else {
            addValue = value;
        }
        return (int) Math.floor(addValue);
    }

    public boolean canGhost() {
        return false;
    }
}
